home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
pctj8412.arc
/
PRIMES.MOD
< prev
next >
Wrap
Text File
|
1986-09-14
|
1KB
|
43 lines
MODULE Primes;
(*
This program performs 10 iterations of finding the prime
numbers among the first 8190 positive integers using
the Eratosthenes Sieve algorithm. It is adapted with
minor changes from a program listed in BYTE magazine,
January 1983.
*)
(* Turn all error checking off: *)
(*$R-*)
(*$S-*)
(*$T-*)
FROM InOut IMPORT WriteLn, WriteInt, WriteString, Write;
CONST Size = 8190;
VAR Flags : ARRAY[0..Size] OF BOOLEAN;
i, prime, k, count, iter : CARDINAL;
BEGIN
WriteString("10 iterations");
WriteLn;
FOR iter := 1 TO 10 DO
count := 0;
FOR i := 0 TO Size DO
Flags[i] := TRUE;
END;
FOR i := 0 TO Size DO
IF Flags[i] THEN
prime := i * 2 + 3;
k := i + prime;
WHILE k <= Size DO
Flags[k] := FALSE;
INC(k, prime);
END;
INC(count);
END;
END;
Write(".");
END;
WriteLn;
WriteInt(count, 6);
WriteString(" primes");
END Primes.